Skip to content

fix(fork): scope task list invalidation to current workspace#4350

Merged
waleedlatif1 merged 2 commits intostagingfrom
improvement/undoredo
Apr 30, 2026
Merged

fix(fork): scope task list invalidation to current workspace#4350
waleedlatif1 merged 2 commits intostagingfrom
improvement/undoredo

Conversation

@waleedlatif1
Copy link
Copy Markdown
Collaborator

Summary

  • `useForkTask` was invalidating `taskKeys.lists()` (all workspaces) instead of `taskKeys.list(workspaceId)` (current workspace only)
  • Pass `workspaceId` through to the hook so invalidation is scoped correctly, matching the pattern of every other task mutation hook (`useDeleteTask`, `useRenameTask`, `useMarkTaskRead`, etc.)
  • Sidebar already refreshes via SSE (`useTaskEvents`) when the fork API publishes a `created` event — the `onSettled` invalidation is a backup and both are now correctly scoped

Type of Change

  • Bug fix

Testing

Tested manually

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 30, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Apr 30, 2026 2:25am

Request Review

@cursor
Copy link
Copy Markdown

cursor Bot commented Apr 30, 2026

PR Summary

Low Risk
Small, localized React Query cache invalidation change; main risk is minor UI staleness if the adjusted useCallback dependency arrays capture outdated mutation instances.

Overview
Fixes task list cache invalidation when forking a chat by updating useForkTask to accept an optional workspaceId and invalidate taskKeys.list(workspaceId) instead of all task lists.

Updates the fork action UI (message-actions.tsx) to pass the current workspaceId into the hook, and trims some Sidebar useCallback dependency arrays around task mutations.

Reviewed by Cursor Bugbot for commit 31a4006. Configure here.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 30, 2026

Greptile Summary

This PR fixes useForkTask to scope its onSettled cache invalidation to the current workspace (taskKeys.list(workspaceId)) instead of all workspaces (taskKeys.lists()), and removes unstable mutation object references from useCallback dependency arrays in sidebar.tsx — both changes align with the established patterns documented in sim-queries.md.

Confidence Score: 5/5

Safe to merge — targeted bug fix with no regressions introduced.

All three changes are correct and follow established project conventions. The invalidation scoping fix matches every other task mutation hook, params.workspaceId is guaranteed non-empty in this URL context, and removal of mutation objects from useCallback deps aligns with the documented TanStack Query v5 stability guarantee in sim-queries.md.

No files require special attention.

Important Files Changed

Filename Overview
apps/sim/hooks/queries/tasks.ts Adds workspaceId param to useForkTask and scopes invalidation to taskKeys.list(workspaceId), matching all other task mutation hooks.
apps/sim/app/workspace/[workspaceId]/components/message-actions/message-actions.tsx Passes params.workspaceId to useForkTask so the hook can scope invalidation correctly.
apps/sim/app/workspace/[workspaceId]/w/components/sidebar/sidebar.tsx Removes mutation objects from useCallback dependency arrays, following the project rule that .mutate() is referentially stable in TanStack Query v5.

Sequence Diagram

sequenceDiagram
    participant UI as MessageActions
    participant Hook as useForkTask(workspaceId)
    participant API as /api/fork
    participant QC as QueryClient

    UI->>Hook: forkTask.mutate(params)
    Hook->>API: POST forkChat(params)
    API-->>Hook: { id: newTaskId }
    Note over Hook,QC: onSettled fires (success or error)
    Hook->>QC: invalidateQueries(taskKeys.list(workspaceId))
    Note over QC: Only refreshes current workspace's task list
    QC-->>UI: Re-fetches tasks for workspaceId
Loading

Reviews (2): Last reviewed commit: "fix(sidebar): remove mutation objects fr..." | Re-trigger Greptile

Mutation objects are not referentially stable in TanStack Query v5 — only
.mutate() and .mutateAsync() are stable. Removed deleteTaskMutation,
deleteTasksMutation, markTaskReadMutation, and markTaskUnreadMutation from
their respective useCallback dependency arrays to avoid unnecessary
recreations on every mutation state update.
@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@cursor review

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 31a4006. Configure here.

@waleedlatif1 waleedlatif1 merged commit 541c1b5 into staging Apr 30, 2026
14 checks passed
@waleedlatif1 waleedlatif1 deleted the improvement/undoredo branch April 30, 2026 02:35
waleedlatif1 added a commit that referenced this pull request Apr 30, 2026
* fix(fork): scope task list invalidation to current workspace

* fix(sidebar): remove mutation objects from useCallback deps

Mutation objects are not referentially stable in TanStack Query v5 — only
.mutate() and .mutateAsync() are stable. Removed deleteTaskMutation,
deleteTasksMutation, markTaskReadMutation, and markTaskUnreadMutation from
their respective useCallback dependency arrays to avoid unnecessary
recreations on every mutation state update.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant